#pragma once
#include <memory>
#include <vector>
#include <map>

#include "TaylorSeries.h"

// This class is an implementation of the progressive QD algorithm, see
// Handbook of Continued Fractions p. 110. Given a set of Taylor         
// coefficients this algorithm is used to generate the partial           
// numerators appearing in the corresponding C-fraction.   
class ProgressiveQD
{
public:
	ProgressiveQD(std::shared_ptr<TaylorSeries> taylorSeries, double c0);
	virtual ~ProgressiveQD(void);

	shared_ptr<vector<double> > partialNumerators(int n);

protected:
	std::vector<double> _vd;

	double c(unsigned int n);
	double d(unsigned int n);
	double e( int k, int l);
	double q( int k, int l);
	std::map<int, std::vector<double> >  _me; 
	std::map<int, std::vector<double> > _mq;
private:
	int _n;
	double _c0; 
	shared_ptr<TaylorSeries> _taylorSeries;
	void initialize(int n);

};

